<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>后台登录</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">
    <style>
    body { background-color: #2f363c; }
    .login { position: fixed; left: 50%; top: 50%; margin: -200px 0 0 -180px; width: 360px; background-color: #fff; }
    .title { height: 60px; line-height: 60px; text-align: center; font-size: 20px; font-weight: bold; }
    </style>
</head>
<body>
    <div class="login layui-panel">
        <div class="layui-card">
            <div class="title layui-card-header">后台登陆</div>
            <div class="layui-card-body">
                <form class="layui-form">
                    <div class="layui-form-item">
                        <div class="layui-input-wrap">
                            <div class="layui-input-prefix"><i class="layui-icon layui-icon-username"></i></div>
                            <input type="text" name="account" value="" lay-verify="required" placeholder="账号" lay-reqtext="请填写账号" autocomplete="off" class="layui-input" lay-affix="clear">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-wrap">
                            <div class="layui-input-prefix"><i class="layui-icon layui-icon-password"></i></div>
                            <input type="password" name="password" value="" lay-verify="required" placeholder="密码" lay-reqtext="请填写密码" autocomplete="off" class="layui-input" lay-affix="eye">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-row">
                            <div class="layui-col-xs6">
                                <div class="layui-input-wrap">
                                    <div class="layui-input-prefix"><i class="layui-icon layui-icon-vercode"></i></div>
                                    <input type="text" name="captcha" value="" lay-verify="required" placeholder="验证码" lay-reqtext="请填写验证码" autocomplete="off" class="layui-input" lay-affix="clear">
                                </div>
                            </div>
                            <div class="layui-col-xs6">
                                <img id="captcha" src="{:captcha_src()}" onclick="this.src='{:captcha_src()}?t=' + new Date().getTime();" style="float: right; height: 38px;">
                            </div>
                        </div>
                    </div>
                      <div class="layui-form-item">
                        <button class="layui-btn layui-btn-fluid" lay-filter="login" lay-submit>登录</button>
                      </div>
                </form>
            </div>
        </div>
    </div>
</body>
</html>
<script src="/static/layui/layui.js"></script>
<script>
layui.use(function() {
    var $ = layui.jquery,
        form = layui.form;

    form.on('submit(login)', function(obj) {
        var loadIndex = layer.load();
        $.post("{:url('admin/login/index')}", obj.field, function(res) {
            if (res.code > 0) {
				layer.alert(res.msg, { icon: 2 });
                $('input[name="captcha"]').val('');
                $('#captcha').attr('src', '{:captcha_src()}?t=' + new Date().getTime());
            } else {
				layer.msg(res.msg, { time: 500 }, function() { 
                    window.location.href = "{:url('admin/index/index')}";
                });
            }
            layer.close(loadIndex);
        });
        return false;
    });
});
</script>